package com.isoft.student.controller;

import com.isoft.student.eo.JurisdictionEOPage;
import com.isoft.student.model.Jurisdiction;
import com.isoft.student.service.JurisdictionService;
import com.isoft.student.tool.ResponseMessage;
import com.isoft.student.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 对外提供数据接口
 */
@Api(tags = "jurisdictionService")
@RestController
public class JurisdictionController {

    @Autowired
    private JurisdictionService jurisdictionService;

    @ApiOperation(value = "权限添加方法")
    @RequestMapping(value = "/addJurisdiction",method = RequestMethod.GET)
    public ResponseMessage add(Jurisdiction jurisdiction){
        int IsAdd = 0;
        //传入数据的判断
        //1.实体对象不能为空
        if (jurisdiction!=null){
            //2.地址不能为空
            if (jurisdiction.getUrl()!=null){
                //3.添加
                IsAdd =jurisdictionService.AddJurisdiction(jurisdiction);
                if (IsAdd == 1) {
                    return Result.success("保存成功");
                } else if (IsAdd == -1) {
                    return Result.error(" 角色重复不允许添加 ");
                } else {
                    return Result.error("保存失败");
                }
            }
        }
        return Result.error("保存失败");
    }

    @ApiOperation(value = "权限修改方法")
    @RequestMapping(value = "/updateJurisdiction",method = RequestMethod.GET)
    public ResponseMessage updateJurisdiction(Jurisdiction jurisdiction){
        //传入的参数不能为空
        if (jurisdiction!=null){
            //参数当中主键不能为0
            if (jurisdiction.getJurisdictionid()!=0){
                if (jurisdictionService.UpdateJurisdiction(jurisdiction)==1){
                    if (jurisdiction.getInterfacename()!=null){
                        if (jurisdiction.getUrl()!=null){

                        }
                    }
                    return Result.success("更新成功");
                }else {
                    return Result.error("更新失败");
                }
            }
        }
        return Result.error("传入的参数不正确");
    }

    @ApiOperation(value = "根据条件获取权限信息")
    @RequestMapping(value = "/getJurisdictionWhereAll",produces = "application/json;charset=utf-8",method=RequestMethod.PUT)
    private ResponseMessage getAll(JurisdictionEOPage jurisdictionEOPage){
        Map<String, List> map=new HashMap<>();
        List<JurisdictionEOPage> listJurisdiction=jurisdictionService.getJurisdictionWhereAll(jurisdictionEOPage);
        map.put("list",listJurisdiction);
        return Result.success("200",map);
    }
}
